<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>demo2练习</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        .delete {
            color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <input type="text" v-model="task.keywords" @keydown.enter="addData()" placeholder="编写任务">
        <div v-for="(item,index) in list" v-if="list.length>0">
            <ul>
                <li>
                    <input type="checkbox" @click="changeStatus(index)">
                    <span :class="{'delete':item.delete}">{{item.keywords}}</span>
                    <button v-on:click="removeTask(index)">删除</button>
                </li>
            </ul>
        </div>
        <div v-if="list.length===0">无数据</div>
    </div>
    <script>
        let app = new Vue({
            el: '#app',
            data: {
                task: {
                    keywords: '',
                    delete: false,
                },
                list: []

            },
            methods: {
                addData: function () {
                    this.list.push(this.task)
                    this.task = {
                        keywords: '',
                        delete: false,
                    }
                },
                changeStatus: function (index) {
                    this.list[index].delete = !this.list[index].delete
                },
                removeTask: function (index) {
                    this.list.splice(index, 1)
                }
            }
        })
    </script>
</body>

</html>